#include <iostream>
using namespace std;

string s;
int y;

int gcd(int x, int y)
{
	return y==0? x: gcd(y, x%y);
}

int main()
{
	cin>>s>>y;
	int num=0, n=s.size();
	for(int i=0; i<=n; i++)
	{
		num=num*10+s[i]-'0';
		num%=y;
	}
	cout<<gcd(num, y);
	return 0;
}
